package com.wd.guiSolicitud;

import com.wd.dominio.Item;
import com.wd.dominio.Producto;
import com.wd.dominio.Tienda;
import com.wd.dominio.Transferencia;
import com.wd.guiSolicitud.particular.ControlGuiTransferencia;
import com.wd.servicios.ControlGeneral;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Gabylis
 */
public class VentanaActualizarTransferencia extends javax.swing.JFrame {

    private ArrayList<Producto> carritoCompra = new ArrayList();

    private DefaultTableModel ModeloOrden = new DefaultTableModel();

    private Transferencia transActual = new Transferencia();

    private Tienda tiendaTrans = new Tienda();

    private Tienda tiendaRecibe = new Tienda();

    private Integer numSol = 0;

    private ControlGuiTransferencia controlTransferencia = new ControlGuiTransferencia();

    private ControlGeneral controlG = ControlGeneral.getInstance();

    private Collection<Producto> productosProve = this.controlG.traerTodosLosProductos();

    /** Creates new form VentanaActualizarTransferencia */
    public VentanaActualizarTransferencia(Transferencia trans) {
        initComponents();

        transActual = trans;
        numSol = transActual.getId();

        this.cargarLabels();

        if (trans.getStatus() != 0) {
            this.buttonEditarProd.setEnabled(false);
        }

        this.panelAgregar.setVisible(false);

         this.carritoCompra = this.controlTransferencia.itemToProducto(transActual.getColeccionProductos());

         this.llenarTabla();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        labelIdTrans = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        labelFechaGen = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        labelFechaEst = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        labelNombreTiendaTrans = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        labelTelefonoTrans = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        labelNombreTiendaRecibe = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        labelTelefonoTiendaRecibe = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaProductos = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        buttonEditarProd = new javax.swing.JButton();
        panelAgregar = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        campoIdProd = new javax.swing.JTextField();
        buttonModProd = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        campoCantidad = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        buttonSalir = new javax.swing.JButton();
        JcEstado = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Consulta/Edicion Transferencias");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Generales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 102))); // NOI18N

        jLabel1.setForeground(new java.awt.Color(0, 0, 102));
        jLabel1.setText("ID TRANSFERENCIA:");

        labelIdTrans.setText("jLabel2");

        jLabel2.setForeground(new java.awt.Color(0, 0, 102));
        jLabel2.setText("FECHA GENERADA: ");

        labelFechaGen.setText("jLabel3");

        jLabel3.setForeground(new java.awt.Color(0, 0, 102));
        jLabel3.setText("FECHA ESTIMADA:");

        labelFechaEst.setText("jLabel4");

        jLabel4.setForeground(new java.awt.Color(0, 0, 102));
        jLabel4.setText("TIENDA QUE TRANSFIERE: ");

        labelNombreTiendaTrans.setText("jLabel5");

        jLabel5.setForeground(new java.awt.Color(0, 0, 102));
        jLabel5.setText("TELÉFONO TIENDA TRANSFIERE:");

        labelTelefonoTrans.setText("jLabel6");

        jLabel6.setForeground(new java.awt.Color(0, 0, 102));
        jLabel6.setText("TIENDA QUE RECIBE:");

        labelNombreTiendaRecibe.setText("jLabel7");

        jLabel7.setForeground(new java.awt.Color(0, 0, 102));
        jLabel7.setText("TELÉFONO TIENDA RECIBE:");

        labelTelefonoTiendaRecibe.setText("jLabel8");

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Imagenes/logo.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(labelIdTrans)
                            .addComponent(jLabel2)
                            .addComponent(labelFechaGen))
                        .addGap(138, 138, 138)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelTelefonoTiendaRecibe)
                            .addComponent(labelNombreTiendaRecibe)
                            .addComponent(labelTelefonoTrans)
                            .addComponent(labelNombreTiendaTrans))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 271, Short.MAX_VALUE)
                        .addComponent(jLabel10)
                        .addGap(40, 40, 40))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(labelFechaEst))
                        .addContainerGap(834, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(labelNombreTiendaTrans))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelIdTrans)
                            .addComponent(jLabel5)
                            .addComponent(labelTelefonoTrans))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel6)
                            .addComponent(labelNombreTiendaRecibe))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelFechaGen)
                            .addComponent(jLabel7)
                            .addComponent(labelTelefonoTiendaRecibe))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(labelFechaEst))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel10)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Productos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 102))); // NOI18N

        tablaProductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tablaProductos);

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Iconos/add.png"))); // NOI18N
        jButton1.setText("Agregar Producto");
        jButton1.setEnabled(false);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Iconos/quit.png"))); // NOI18N
        jButton2.setText("Eliminar Producto");
        jButton2.setEnabled(false);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Iconos/agt_action_success.png"))); // NOI18N
        jButton3.setText("Actualizar Orden");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        buttonEditarProd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Iconos/edit.png"))); // NOI18N
        buttonEditarProd.setText("Editar Producto");
        buttonEditarProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarProdActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buttonEditarProd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(50, 50, 50))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addGap(30, 30, 30)
                .addComponent(jButton2)
                .addGap(29, 29, 29)
                .addComponent(buttonEditarProd)
                .addGap(30, 30, 30)
                .addComponent(jButton3)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        panelAgregar.setBorder(javax.swing.BorderFactory.createTitledBorder("Editar Producto"));

        jLabel11.setText("Id producto:");

        buttonModProd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/wd/gui/Iconos/edit.png"))); // NOI18N
        buttonModProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonModProdActionPerformed(evt);
            }
        });

        jLabel13.setText("Cantidad:");

        javax.swing.GroupLayout panelAgregarLayout = new javax.swing.GroupLayout(panelAgregar);
        panelAgregar.setLayout(panelAgregarLayout);
        panelAgregarLayout.setHorizontalGroup(
            panelAgregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAgregarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAgregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoIdProd, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                    .addComponent(jLabel11)
                    .addGroup(panelAgregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(campoCantidad, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(buttonModProd, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        panelAgregarLayout.setVerticalGroup(
            panelAgregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAgregarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoIdProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(buttonModProd)
                .addContainerGap(56, Short.MAX_VALUE))
        );

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setText("Estado de la Solicitud:");

        buttonSalir.setText("Salir");
        buttonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSalirActionPerformed(evt);
            }
        });

        JcEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "APROBADA", "DESPACHADA", "RECIBIDA", "CANCELADA" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(JcEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(buttonSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(panelAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
                .addGap(22, 22, 22))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(JcEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49)
                .addComponent(buttonSalir)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonEditarProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarProdActionPerformed
        int seleccion = -1;
        seleccion = this.tablaProductos.getSelectedRow();
        if (seleccion >= 0) {
            Producto pr = this.carritoCompra.get(seleccion);
            this.campoIdProd.setText(String.valueOf(pr.getId()));
            this.campoCantidad.setText(String.valueOf(pr.getCantidad()));
            this.panelAgregar.setVisible(true);
        }
    }//GEN-LAST:event_buttonEditarProdActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        int Status = this.JcEstado.getSelectedIndex();
        this.transActual.setStatus(Status);
        Collection<Item> coleccionItems = this.controlTransferencia.productoToItem(carritoCompra, transActual.getId());
        this.transActual.setColeccionProductos(coleccionItems);
        this.controlTransferencia.actualizarTransferencia(transActual);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void buttonModProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonModProdActionPerformed
        String idProductoColocado = this.campoIdProd.getText();
        String cantidad = this.campoCantidad.getText();
        if ((!idProductoColocado.equals("")) && (!cantidad.equals(""))) {
            Integer idProduSel = Integer.parseInt(idProductoColocado);
            Integer cantidadidProd = Integer.parseInt(cantidad);
            this.agregarElementoCarrito(idProduSel, cantidadidProd);
            this.tablaProductos.removeAll();
            this.llenarTabla();
            this.campoIdProd.setText("");
            this.campoCantidad.setText("");
        }
}//GEN-LAST:event_buttonModProdActionPerformed

    private void buttonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSalirActionPerformed
        this.dispose();
}//GEN-LAST:event_buttonSalirActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run(Transferencia trans) {
                new VentanaActualizarTransferencia(trans).setVisible(true);
            }
            public void run() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox JcEstado;
    private javax.swing.JButton buttonEditarProd;
    private javax.swing.JButton buttonModProd;
    private javax.swing.JButton buttonSalir;
    private javax.swing.JTextField campoCantidad;
    private javax.swing.JTextField campoIdProd;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelFechaEst;
    private javax.swing.JLabel labelFechaGen;
    private javax.swing.JLabel labelIdTrans;
    private javax.swing.JLabel labelNombreTiendaRecibe;
    private javax.swing.JLabel labelNombreTiendaTrans;
    private javax.swing.JLabel labelTelefonoTiendaRecibe;
    private javax.swing.JLabel labelTelefonoTrans;
    private javax.swing.JPanel panelAgregar;
    private javax.swing.JTable tablaProductos;
    // End of variables declaration//GEN-END:variables

    private Producto obtenerElementoRepetido(int idProducto) {
        Producto resultado = null;
        for (Producto producto : carritoCompra) {
            if (idProducto == producto.getId()) {
                resultado = producto;
            }
        }
        return resultado;
    }

    private boolean existeElementoEnCarrito(int idProducto) {
        boolean resultado = false;
        for (Producto producto : carritoCompra) {
            if (idProducto == producto.getId()) {
                resultado = true;
            }
        }
        return resultado;
    }

    private int obtenerCantidadRepetida(int idProducto) {
        int resultado = 0;
        for (Producto producto : carritoCompra) {
            if (idProducto == producto.getId()) {
                resultado = producto.getDepartamentoId();
            }
        }
        return resultado;
    }

    private int obtenerindiceProblematico(int idProducto) {
        int resultado = 0;
        for (Producto producto : carritoCompra) {
            if (idProducto == producto.getId()) {
                resultado = carritoCompra.indexOf(producto);
            }
        }
        return resultado;
    }

    private void agregarElementoCarrito(int idProdcuto, int cantidad) {
        for (Producto producto : productosProve) {
            if (producto.getId() == idProdcuto) {
                if (this.existeElementoEnCarrito(idProdcuto)) {
                    Producto productoRepe = this.obtenerElementoRepetido(idProdcuto);
                    int cantidaActual = this.obtenerCantidadRepetida(idProdcuto);
                    int cantidadTotal = cantidad;
                    producto.setCantidad(cantidadTotal);
                    this.carritoCompra.add(producto);
                    int indiceP = this.obtenerindiceProblematico(idProdcuto);
                    this.carritoCompra.remove(productoRepe);
                } else {
                    producto.setCantidad(cantidad);
                    this.carritoCompra.add(producto);
                }
            }
        }
    }

    private void eliminarElementoCarrito(int productoId) {
        int indiceP = this.obtenerindiceProblematico(productoId);
        this.carritoCompra.remove(indiceP);
    }

    public void buscarTiendasTrans(){

        Collection<Tienda> tiendas = new Vector();
        tiendas = controlG.traerTodasLasTienda();

        for (Tienda tienda : tiendas) {
            if (tienda.getCodigo() == transActual.getIdTiendaQueTransfiere()){
                this.tiendaTrans = tienda;
            }
            if (tienda.getCodigo() == transActual.getIdTiendaQueRecibe()){
                this.tiendaRecibe = tienda;
            }
        }
    }

    public void cargarLabels(){
        this.buscarTiendasTrans();

        this.labelIdTrans.setText(numSol.toString());
        this.labelFechaGen.setText(transActual.getFechaGenerada().toString());
        this.labelFechaEst.setText(transActual.getFechaEstimada().toString());
        this.labelNombreTiendaTrans.setText(tiendaTrans.getNombre());
        this.labelTelefonoTrans.setText(tiendaTrans.getTelefono());
        this.labelNombreTiendaRecibe.setText(tiendaRecibe.getNombre());
        this.labelTelefonoTiendaRecibe.setText(tiendaRecibe.getTelefono());
    }

    private void llenarTabla() {
        ModeloOrden = new DefaultTableModel();
        ModeloOrden.addColumn("Id");
        ModeloOrden.addColumn("Nombre");
        ModeloOrden.addColumn("Descripción");
        ModeloOrden.addColumn("Cantidad");

        for (Producto p : carritoCompra) {
            Vector info = new Vector();
            info.addElement(p.getId());
            info.addElement(p.getNombre());
            info.addElement(p.getDescripcion());
            info.addElement(p.getCantidad());
            this.ModeloOrden.addRow(info);
        }
        this.tablaProductos.setModel(ModeloOrden);
    }
}
